#include "change_bk.h"
#include "ui_change_bk.h"
#include "processing.h"
#include "mainwindow.h"
#include"qt_cv_change.h"
#include<QDebug>
int R,G,B;
change_bk::change_bk(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::change_bk)
{
    ui->setupUi(this);
}

change_bk::~change_bk()
{
    delete ui;
}
void change_bk::choosepic(){
    QString curDir=QDir::currentPath();//选择文件
    QString filename=QFileDialog::getOpenFileName(this,"select Image",curDir,
                                                          "Images (*.png *.bmp *.jpg *.tif *.GIF )");
    QImage* img=new QImage;
    if(! ( img->load(filename) ) ) //加载图像
    {
             qDebug()<<"打开图像失败";
             //ui->debugEdit->append("打开图像失败");
         delete img;
         return;
    }
    *img = img->convertToFormat(QImage::Format_RGB32);
    maskbk = QImage2cvMat(*img);
    cvtColor(maskbk,maskbk,COLOR_RGBA2RGB);
    delete img;
}

void change_bk::choosecolor(int& b,int& g,int& r){
    switch (ui->comboBox->currentIndex()) {
    case 1:
        b=219;
        g=142;
        r=67;
        qDebug()<<"yes";
        break;
    case 2:
        b=255;
        g=255;
        r=255;
        break;
    case 3:
        b=0;
        g=0;
        r=255;
        break;
    case 0:
    case 4:
        b=0;
        g=0;
        r=0;
        break;
    default:
        break;
    }
    qDebug()<<ui->comboBox->currentIndex();
}


void change_bk::on_comboBox_currentIndexChanged(const QString &arg1)
{
    choosecolor(B,G,R);
    if(ui->comboBox->currentIndex()==0){
        choosepic();
        cv::resize(maskbk,maskbk,Size(dstImage.cols,dstImage.rows),0,0,INTER_AREA);
        //maskbk.cols=dstImage.cols;
        //maskbk.rows=dstImage.rows;
        //dstImage+=maskImage;
        //dstImage=maskImage;
    }
}
